package com.bridge.bridge_wd.activity;

import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.bridge.bridge_wd.R;
import com.bridge.bridge_wd.adapter.QianDaoAdapter;
import com.bridge.bridge_wd.databinding.ActivityQiandaoBinding;
import com.bridge.common.base.BaseActivity;
import com.bridge.common.utils.UltimateBarXUtils;
import com.yechaoa.yutils.DisplayUtil;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;

/**
 * @ClassName QianDaoActivity
 * @Description 签到
 * @Author xushufeng
 * @CreateDate 2021/4/16 0016 10:04
 * @Version 1.0
 * @UpdateDate 2021/4/16 0016 10:04
 * @UpdateRemark 更新说明
 */
public class QianDaoActivity extends BaseActivity {
    ActivityQiandaoBinding binding;
   List<String> stringList=new ArrayList<>();
    QianDaoAdapter qianDaoAdapter;
    @Override
    protected int layoutId() {
        return R.layout.activity_qiandao;
    }

    @Override
    protected void initView() {
        binding = getBind();
        UltimateBarXUtils.setNoAppBar(QianDaoActivity.this);
        binding.titleView.post(new Runnable() {
            @Override
            public void run() {
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(0, DisplayUtil.getStatusBarHeight(), 0, 0);//4个参数按顺序分别是左上右下
                binding.titleView.setLayoutParams(layoutParams);
            }
        });
        Calendar cal = Calendar.getInstance();

        int year = cal.get(Calendar.YEAR);
        int month = (cal.get(Calendar.MONTH))+1;
        binding.tvMonth.setText(year+"-"+month);
        //当前月的第几天：即当前日
        int day_of_month = cal.get(Calendar.DAY_OF_MONTH);
        for (int i=0;i<getCurrentMonthLastDay();i++){
            stringList.add((i+1)+"");
        }
        GridLayoutManager gridLayoutManager=new GridLayoutManager(this,7);
        qianDaoAdapter=new QianDaoAdapter(this,stringList,day_of_month+"");
        binding.timeRecycleview.setLayoutManager(gridLayoutManager);
        binding.timeRecycleview.setAdapter(qianDaoAdapter);
    }

    @Override
    protected void setListenner() {

    }

    /**
     * 取得当月天数
     * */
    public static int getCurrentMonthLastDay()
    {
        Calendar a = Calendar.getInstance();
        a.set(Calendar.DATE, 1);//把日期设置为当月第一天
        a.roll(Calendar.DATE, -1);//日期回滚一天，也就是最后一天
        int maxDate = a.get(Calendar.DATE);
        return maxDate;
    }
}
